/** @jsxImportSource @emotion/react */
import * as React from "react";
import {CCell, Cell, Table, TableBody, TableHead, TableRow, Text,} from "customize-easy-ui-component";
import {DirectLink} from "../../routing/Link";
import {useJudgmentTable} from "../hook/useJudgment";
import {twoForkSelect} from "../common/base";


//对比的：<RouterLink 可以导航文本处鼠标和点过链接颜色变但是表格鼠标不变，不能放在表格内。 改<DirectLink的。
/**@property config : 配置 测量数据
 * @property nseq : 有无序号列, 默认有的
 * @property crit : 真的有“判断标准”这个列的， 默认没有；
 * */
export const 测量判定结果= ({ orc, rep,label,config,children,fixed=["3%","6%","4%","13%","%","5%","12%","10%","8%","6%"],tag='Measure',nseq,crit} :
          { orc: any, rep: any,label:string,config:any,children?:any,fixed?:string[],tag?:string,nseq?:boolean,crit?:boolean}
) => {
    const renderMeasure=useJudgmentTable({rep,orc, config,nseq});
    return <>
        <Text variant="h4" css={{marginTop: '1rem', "@media print": {paddingBottom: '3.5rem', pageBreakInside: 'avoid'}
        }}>{label}</Text>
        <Table fixed={fixed} tight  miniw={800} css={ {borderCollapse: 'collapse', "@media print": {marginTop: '-3.5rem'}} } >
            <TableHead>
                <TableRow>
                    {!nseq &&<CCell><Text css={{fontSize:'0.8rem'}}>序号</Text></CCell>}
                    <CCell colSpan={2}><Text css={{fontSize:'0.7rem'}}>项目编号</Text></CCell><CCell colSpan={2}>观测内容</CCell>
                    <CCell>单位</CCell>
                    {crit && <CCell>判断标准</CCell>}
                    <CCell>观测数据</CCell><CCell>测量结果</CCell><CCell><Text css={{fontSize:'0.8rem'}}>结果判定</Text></CCell>
                </TableRow>
            </TableHead>
            <TableBody>
                <DirectLink  href={`/report/${rep?.modeltype}/ver/${rep?.modelversion}/${rep?.id}/${tag}?original=1#${tag}`}>
                    {renderMeasure}
                </DirectLink>
            </TableBody>
        </Table>
    </>;
};

/**格式化检验记录：【特殊表现的表格】表格行列倒置布局形式的;
 * */
export const 现场检验= ( { orc, rep } : { orc: any, rep: any}
) => {
    const recNums=orc?.检验条件?.length;
    const blocks=Math.ceil(recNums/5) || 1;     //倒转的，每5行的一块块布局:固定的5个日期汇集打印的一行。
    return <>
        <Table fixed={ ["3.5%","%","11%","11%","11%","11%","11%"] }  css={ {borderCollapse: 'collapse' } } tight  miniw={800}>
            <TableHead>
                <TableRow>
                    <CCell colSpan={2}>现场检验条件</CCell>
                    <CCell>确认结果</CCell><CCell>确认结果</CCell><CCell>确认结果</CCell><CCell>确认结果</CCell><CCell>确认结果</CCell>
                </TableRow>
            </TableHead>
            <TableBody>
                {(new Array(blocks)).fill(null).map((_, b:number) => {
                    // const dateE=orc?.检验条件?.[b];    //某一次的
                    const condit1=[] as any, condit2=[] as any, dates=[] as any;
                    (new Array(5)).fill(null).forEach((_, d:number) => {
                        if(b*5 +d>=recNums){
                            condit1.push(<CCell key={b*5 +d}></CCell>);
                            condit2.push(<CCell key={b*5 +d}></CCell>);
                            dates.push(<CCell key={b*5 +d}></CCell>);
                        }
                        else{
                            const row=orc?.检验条件?.[b*5 +d];
                            condit1.push(<CCell key={b*5 +d}>{twoForkSelect(row?.x)}</CCell>);
                            condit2.push(<CCell key={b*5 +d}>{twoForkSelect(row?.y)}</CCell>);
                            dates.push(<CCell key={b*5 +d}>{row?.d}</CCell>);
                        }
                    });
                    return <DirectLink key={b} href={`/report/${rep?.modeltype}/ver/${rep?.modelversion}/${rep?.id}/SiteCondition#SiteCondition`}>
                        <TableRow>
                            <CCell>1</CCell><Cell>试验的动力源、环境温度、海拔高度、风速符合标准和设计要求。</Cell>
                            {condit1}
                        </TableRow>
                        <TableRow>
                            <CCell>2</CCell><Cell>检验现场不得有易燃、易爆以及腐蚀性气体。</Cell>
                            {condit2}
                        </TableRow>
                        <TableRow>
                            <CCell colSpan={2}>确认时间</CCell>
                            {dates}
                        </TableRow>
                    </DirectLink>;
                }) }
            </TableBody>
        </Table>;
        注：每次到现场后，在检验前应对检验条件进行确认，只有确认所有与检验相关的条件满足检验要求时，才能开始开展检验工作。
    </>;
};

